from tortoise import fields
from datetime import datetime
from .base import BaseModel, TimestampMixin


class SysJob(BaseModel, TimestampMixin):
    """定时任务调度表"""

    job_id = fields.IntField(pk=True, description="任务ID")

    job_name = fields.CharField(max_length=64, description="任务名称")

    job_group = fields.CharField(max_length=64, description="任务组名")

    invoke_target = fields.CharField(max_length=500, description="调用目标字符串")

    cron_expression = fields.CharField(max_length=255, null=True, description="cron执行表达式")

    misfire_policy = fields.CharField(max_length=20, null=True, description="计划执行错误策略（1立即执行 2执行一次 3放弃执行）")

    concurrent = fields.CharField(max_length=1, null=True, description="是否并发执行（0允许 1禁止）")

    job_status = fields.CharField(max_length=1, null=True, description="任务状态（0正常 1暂停）")

    status = fields.CharField(max_length=1, null=True, description="状态（0正常 2删除）")

    create_by = fields.CharField(max_length=64, null=True, description="创建者")

    create_time = fields.DatetimeField(null=True, description="创建时间")

    update_by = fields.CharField(max_length=64, null=True, description="更新者")

    update_time = fields.DatetimeField(null=True, description="更新时间")

    remark = fields.CharField(max_length=500, null=True, description="备注信息")

    class Meta:
        table = "sys_job"

    def __str__(self):
        return f"{self.job_group}"